from typing import List


class Solution:
    def removeSubfolders2(self, folder: List[str]) -> List[str]:
        del_arr = set()
        for i in range(len(folder)):
            temp = folder[i]+'/'
            for k in range(len(folder)):
                if i != k and len(folder[k]) > len(temp) and (temp in folder[k]) and folder[k].index(temp) == 0:
                    del_arr.add(folder[k])

        res_arr = []
        for s in folder:
            if s not in del_arr:
                res_arr.append(s)

        return res_arr

    def removeSubfolders(self, folder: List[str]) -> List[str]:
        folder.sort()
        res_arr = [folder[0]]
        for k in range(1, len(folder)):
            temp_len = len(res_arr[-1])
            if len(folder[k]) <= temp_len or (res_arr[-1]+'/') != folder[k][:temp_len+1]:
                res_arr.append(folder[k])
        return res_arr


print(Solution().removeSubfolders(["/a/b/c","/a/b/ca","/a/b/d"]))
